
******CLIENT OUTCOMES (TABLE 4)********

set more off
clear all 
clear matrix
capture log close

adopath + "$main/DoFiles"																		


local seed = 999
local reps = 5000


		
//--> CLIENT-LEVEL DATA 
	*********************************************************************************************************************************************************
		
		//-->FROM GINE AND MANSURI (FORTHCOMING) STUDY BASELINE SURVEY, SEC H
		//--> ONLY SUBSET OF COS THAT OVERLAP W/ THIS STUDY COS		
		
		
		use "$data/LT_secH.dta"
		
			//--> HH SIZE
			
					egen hh_size = rowtotal(hh_students_away hh_migrants_away hh_mem_present)
					
		
			//--> THREE EMPOWERMENT DUMMY VARAIBLES
			
				//--> 1 = MORE SINCE JULY 2005, 0 = REST (EQUAL, LESS, NOT APPLICABLE)
				
				recode non_credit_discuss buy_sell_collectively leadership_advice (1=1) (0 2 3 = 0)
		
			//--> EMPOWERMENT INDEX
			
				egen empowerment_index = rowmean(non_credit_discuss buy_sell_collectively leadership_advice)
		
			//--> CO TREATMENT ASSIGNMENT (TREATMENT, FU, REGION)
			
						preserve
						use "$data/FWCO_panel.dta", clear
						sort fw_code
						merge fw_code using "$data/FWHR.dta"
						drop _merge
						
						keep if month>=11
						
						//--> FEW COS w/ CHANGING FU TREATMENT STATUS--> ASSIGN THE MODE TREATMENT/FU
						
									bys co_code: egen treat_co = mode(treat), maxmode
									bys co_code: egen treat_credit_co = mode(treat_credit), maxmode
									bys co_code: egen treat_sm_co = mode(treat_sm), maxmode

									bys co_code: egen fu_feb05_co = mode(fu_feb05), maxmode
									bys co_code: egen region_co = mode(region), maxmode			
						
						
						keep co_code treat_co treat_credit_co treat_sm_co fu_feb05_co region_co
						bys co_code: keep if _n==1
						sort co_code 
						tempfile temp_treat
						save `temp_treat'
						restore
		
				sort co_code
				merge co_code using `temp_treat', nok
				drop _m
				
				
		
			//--> REGION DUMMIES
					
					tab region_co, gen(r)
							
							

//--> OUTPUT: TABLE 4 (CLIENT OUTCOMES: DUMMY VARS AND INDEX)	
	*********************************************************************************************************************************************************
	
		local client_var buy_sell_collectively leadership_advice non_credit_discuss empowerment_index
		

	
		//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************		
	
			local replace replace
			foreach v in `client_var'{
				reg `v' r1 r2 treat_credit_co treat_sm_co
				sum `v' if treat_co==0 
				local m = r(mean)
				outreg2 using "$output/table4 (coeff).xls", `replace' addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit_co treat_sm_co) nocons nor2
				local replace
				}
				
			
				
		log using "$output/table4 (p-values)", replace	
		
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
					foreach v in `client_var' {
						cgmwildboot `v' r1 r2 treat_credit_co treat_sm_co, cluster(fu_feb05_co) bootcluster(fu_feb05_co) seed(`seed') 
						}
					
							
			//--> CREDIT VS. SOCIAL
			
					g x1 = treat_credit_co + treat_sm_co
					g test1 = treat_credit_co //RELEVANT VAR FOR F TEST
						
					foreach v in `client_var' {
						cgmwildboot `v' r1 r2 x1 test1, cluster(fu_feb05_co) bootcluster(fu_feb05_co) seed(`seed') 
						}
					

		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
					foreach v in `client_var' {
						randcmd((treat_credit_co treat_sm_co) reg `v' treat_credit_co treat_sm_co r1 r2, cluster(fu_feb05_co)), treatvars(treat_credit_co treat_sm_co) groupvar(fu_feb05_co) reps(`reps') seed(`seed')	
						}
							
			//--> CREDIT VS. SOCIAL (F TEST)
					
					foreach v in `client_var' {
						randcmd((treat_credit_co) reg `v' treat_credit_co x1 r1 r2, cluster(fu_feb05_co)), treatvars(treat_credit_co treat_sm_co) groupvar(fu_feb05_co) reps(`reps') seed(`seed') calc1(replace x1 = treat_credit_co + treat_sm_co)
						}
			
	log close
	*********************************************************************************************************************************************************

	
						
	
//--> OUTPUT: ONLINE APPENDIX TABLE D.2 (BALANCE TEST ON CLIENT VARS)	
	*********************************************************************************************************************************************************
	
		local var_longlist age female hh_head education hh_size hh_num_children
		
		g bonus_status = 0 if treat_co==0
		replace bonus_status = 1 if treat_credit_co ==1
		replace bonus_status = 2 if treat_sm_co ==1
		
		
		//--> COLUMNS 1-3: MEANS BY TREATMENT STATUS
			*****************************************
		
				putexcel set "$output/tableD_2 (col1-3)", replace
					putexcel A1 = "var name"
					putexcel B1 = "no bonus"
					putexcel C1 = "credit bonus"
					putexcel D1 = "social bonus"
				
				local count = 2
				foreach v in `var_longlist' {
					mean `v', over (bonus_status)
						putexcel A`count' = "`v'"
						putexcel B`count' = matrix(e(b))
					local count = `count' + 1
					}
					
					putexcel A`count' = "No. of clients"
					putexcel B`count' = matrix(e(_N))
		


		//--> COLUMNS 4-6: RANDOMIZATION INFERENCE BASED P VALUES
			****************************************		
				
				log using "$output/tableD_2 (col4-6)", replace	
			
						
				//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL		

						foreach v in `var_longlist' {
							randcmd((treat_credit_co treat_sm_co) reg `v' treat_credit_co treat_sm_co, cluster(fu_feb05_co)), treatvars(treat_credit_co treat_sm_co) groupvar(fu_feb05_co) reps(`reps') seed(`seed')	
							}	
				
				//--> CREDIT VS. SOCIAL

						foreach v in `var_longlist' {
							randcmd((treat_credit_co) reg `v' treat_credit_co x1, cluster(fu_feb05_co)), treatvars(treat_credit_co treat_sm_co) groupvar(fu_feb05_co) reps(`reps') seed(`seed') calc1(replace x1 = treat_credit_co + treat_sm_co)
							}	
		
			
				//--> WESTFALL YOUNG OMIBUS TEST
	
					#delimit ;				
					randcmd ((treat_credit_co treat_sm_co) reg hh_head treat_credit_co treat_sm_co, cluster(fu_feb05_co)) ((treat_credit_co treat_sm_co) reg hh_num_children treat_credit_co treat_sm_co, cluster(fu_feb05_co)) ((treat_credit_co treat_sm_co) reg female treat_credit_co treat_sm_co, cluster(fu_feb05_co))
							((treat_credit_co treat_sm_co) reg age treat_credit_co treat_sm_co, cluster(fu_feb05_co)) ((treat_credit_co treat_sm_co) reg education treat_credit_co treat_sm_co, cluster(fu_feb05_co)) ((treat_credit_co treat_sm_co) reg hh_size treat_credit_co treat_sm_co, cluster(fu_feb05_co))						
							((treat_sm_co) reg hh_head treat_sm_co if treat_co==1, cluster(fu_feb05_co)) ((treat_sm_co) reg hh_num_children treat_sm_co if treat_co==1, cluster(fu_feb05_co)) ((treat_sm_co) reg female treat_sm_co if treat_co==1, cluster(fu_feb05_co))
							((treat_sm_co) reg age treat_sm_co if treat_co==1, cluster(fu_feb05)) ((treat_sm_co) reg education treat_sm_co if treat_co==1, cluster(fu_feb05)) ((treat_sm_co) reg hh_size treat_sm_co if treat_co==1, cluster(fu_feb05))						
							, treatvars(treat_credit_co treat_sm_co) groupvar(fu_feb05_co)reps(`reps') seed(`seed'); 
					
					#delimit cr
					
		log close			
		

	*********************************************************************************************************************************************************

	
